import axiosInstance from '@/utils/request.js'

/**
 * 登录接口
 * @param {*} username 
 * @param {*} password 
 * @returns 
 */
export const RequestLogin = (username,password) => {
    return axiosInstance({
        method: 'post',
        url: '/api/login',
        //post请求参数使用data选项, get参数 params选项
        data: {
            username,
            password,
        },
    })
}

/**
 * 登录接口 -- 我的数据库
 * @param {*} username 
 * @param {*} password 
 * @returns 
 */
export const RequestLoginBS = (username,password) => {
    return axiosInstance({
        method: 'post',
        url: '/operator/login',
        //post请求参数使用data选项, get参数 params选项
        data: {
            username,
            password,
        },
    })
}

/**
 * 产品列表
 *   shopKey: 店铺名称
 *   productKey: 产品名称
 * @returns 
 */
export const RequestShopList = (pageNo,pageSize,productKey,shopKey,startPrice,endPrice)=>{
    return axiosInstance({
        method:'get',
        url:'/api/shop',
        params:{
            pageSize,
            pageNo,
            productKey,
            shopKey,
            startPrice,
            endPrice
        }
    })
}

/**
 * 产品分类
 */
export const RequestCatgoryList = ()=>{
    return axiosInstance({
        method:'get',
        url:'/api/category'
    })
}

/**
 * 添加产品
 */
export const RequestAddGoods = (formData)=>{
    // const token = localStorage.getItem('TOKEN')
    return axiosInstance({
        method:'post',
        url:'/api/shop/insert',
        headers: { 'Content-Type': 'multipart/form-data'},
        data:formData
    })
}

/**
 * 删除产品
 */
export const RequestDeleteGoods = (id)=>{
    // const token = localStorage.getItem('TOKEN')
    return axiosInstance({
        method:'get',
        url:'/api/shop/delete',
        // headers: { 'Authorization':token },
        params:{
            id
        }
    })
}

/**
 * 添加产品
 */
export const RequestUpdateGoods = (formData)=>{
    // const token = localStorage.getItem('TOKEN')
    return axiosInstance({
        method:'post',
        url:'/api/shop/edit',
        headers: { 'Content-Type': 'multipart/form-data' },
        data:formData
    })
}

/**
 * 批量删除
 *  ids: 商品id '1,2,3,4'
 */
export const RequestBatchDelete = (ids)=>{
    return axiosInstance({
        method:'get',
        url:'/api/shop/batchdelete',
        params:{
            ids
        }
    })
}


/**
 * 商家列表
 */
 export const RequestStoreList = ()=>{
    return axiosInstance({
        method:'get',
        url:'/api/store'
    })
}